﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using ModelQuality.Metrics.Rules;

namespace ModelQuality.Metrics.Configuration
{
    class ConfigurationHelper
    {
        public ModelValidation ParseXmlConfiguration(FileInfo xmlConfiguration)
        {
            String xml = File.ReadAllText(xmlConfiguration.FullName);
            return DefaultUnmarshall<ModelValidation>(xml);
        }

        private T DefaultUnmarshall<T>(String xml) where T : class
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            T ret = serializer.Deserialize(new StringReader(xml)) as T;

            return ret;
        }
    }
}
